package com.example.demo.service.impl;

import com.example.demo.dao.CourseDao;
import com.example.demo.dao.StudentDao;
import com.example.demo.entity.CourseBean;
import com.example.demo.entity.StudentBean;
import com.example.demo.service.CourseService;
import com.example.demo.service.StudentService;
import com.example.demo.util.PageEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;
    @Override
    public List<StudentBean> all() {
        return studentDao.getAll();
    }

    @Override
    public Integer add(StudentBean studentBean) {
        return studentDao.insert(studentBean);
    }


    @Override
    public Integer update(StudentBean  studentBean) {
        return studentDao.edit(studentBean);
    }

    @Override
    public Integer delete(Integer id) {
        return studentDao.del(id);
    }

    @Override
    public StudentBean  one(Integer id) {
        return studentDao.getOne(id);
    }

    @Override
    public PageEntity list(Integer pageNo, Integer pageSize,String address,String name,String sortOrder) {

        // 根据页码 求 跳过多少条数据
        Integer jump = (pageNo-1)*pageSize;

        Integer count = studentDao.getCount(address, name);
        List<StudentBean > rows = studentDao.getPage(jump, pageSize, address, name, sortOrder);


        PageEntity<List> listPageEntity = new PageEntity<List>(rows,count);
        return listPageEntity;
    }

}

